from math import sqrt
# 作业：
# 1.把昨天封装的Math类中的实例方法改为静态方法, 体会一下两者的区别


class MyMath:
    def __init__(self):
        print("开始计算...")

    @staticmethod
    def addition(x, y):
        return x + y

    @staticmethod
    def subtraction(x, y):
        return x - y

    @staticmethod
    def multiplication(x, y):
        return x * y

    @staticmethod
    def division(x, y):
        return x / y

    @staticmethod
    def power(x, y):
        return x ** y

    @staticmethod
    def evolution(x):
        return sqrt(x)


# 2.昨天大家将身边的事物抽象出一个类, 在此基础上添加以下功能:
#   在类中创建类属性
#   在类中创建私有属性
#   在__init__中初始化实例属性
#   在__init__中初始化实例私有属性
#   通过类方法来获取类的私有属性
#   在自己的类中实现__str__
class NetworkEquipment:
    def __init__(self, name):
        self.name = name
        print("初始化该网络设备")

    def vendors(self, v):
        print(f"该网络设备的厂商是：{v}")

    def __str__(self):
        print(f"该网络设备是{self.name}")


class SafetyEquipment:
    def __init__(self, name):
        self.name = name
        print("初始化该安全设备")

    def vendors(self, v):
        print(f"该安全设备的厂商是：{v}")

    def __str__(self):
        print(f"该安全设备是{self.name}")


# 多继承
class FireWall(NetworkEquipment, SafetyEquipment):
    func = "安全防护"
    __SupportRouting = True

    def __init__(self, name):
        self.vendor = ""
        self.__name = name
        self.t = __class__.__name__
        print("该设备既是网络设备，也是安全设备")
        super(FireWall, self).__init__(self.__name)
        super(NetworkEquipment, self).__init__(self.name)

    def vendors(self, v):
        self.vendor = v

    @classmethod
    def support(cls):
        return cls.__SupportRouting

    def __str__(self):
        print(f"打印信息：该设备是{self.__name},厂商是{self.vendor}")


if __name__ == "__main__":
    # 使用静态方法，不用创建实例，可以直接通过类调用函数
    print(f"加法运算：{MyMath.addition(1, 2)}")
    print(f"减法运算：{MyMath.subtraction(3, 9)}")
    print(f"乘法运算：{MyMath.multiplication(2, 8)}")
    print("除法运算：" + "{:.2f}".format(MyMath.division(134, 9)))
    print(f"幂运算：{MyMath.power(2, 3)}")
    print(f"开方运算：{MyMath.evolution(64)}")
    print()

    # 创建实例
    device1 = NetworkEquipment("Switch")
    device1.__str__()
    print()
    print(f"防火墙功能是{FireWall.func}")
    print(f"防火墙是否支持路由功能：{FireWall.support()}")
    my_device = FireWall("Hillstone")
    my_device.vendors("山石")
    my_device.__str__()
